package com.ljph.kit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by yuzhou on 16/12/25.
 */
public class DateKit {

  private static final Logger _log = LoggerFactory.getLogger(DateKit.class);

  public static Date Str2Date(String str) {
    return Str2Date(str, "yyyy-MM-dd HH:mm:ss");
  }

  public static Date Str2Date(String str, String fmt) {

    SimpleDateFormat df = new SimpleDateFormat(fmt);
    Date date = null;

    try {
      date = df.parse(str);
    } catch (ParseException e) {
      _log.error("Fail to parse date string {} with format {}", str, fmt);
    }

    return date;
  }
}
